package cn.leida.ruoyi.system.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.leida.common.json.util.JsonCopyUtil;
import cn.leida.ruoyi.common.core.domain.entity.SysMenu;
import cn.leida.ruoyi.common.core.domain.entity.SysRole;
import com.alibaba.fastjson2.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lei
 * @create 2025-03-25 0:38
 */
public class SysJsonUtil {

    public static List<SysMenu> toSysMenuList(List<JSONObject> jsonObjectList) {
        List<SysMenu> menuList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(jsonObjectList)) {
            // 将sql字段转为java字段(两者都包含)
            List<JSONObject> beanJsonList = JsonCopyUtil.javaFieldJsonList(SysMenu.class, jsonObjectList);
            for (JSONObject json : beanJsonList) {
                SysMenu sysMenu = json.toJavaObject(SysMenu.class);
                sysMenu.initBean();
                menuList.add(sysMenu);
            }
        }
        return menuList;
    }

    public static List<SysRole> toSysRoleList(List<JSONObject> jsonObjectList) {
        List<SysRole> menuList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(jsonObjectList)) {
            // 将sql字段转为java字段(两者都包含)
            List<JSONObject> beanJsonList = JsonCopyUtil.javaFieldJsonList(SysRole.class, jsonObjectList);
            for (JSONObject json : beanJsonList) {
                SysRole sysRole = json.toJavaObject(SysRole.class);
                menuList.add(sysRole);
            }
        }
        return menuList;
    }
}
